<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//文章管理控制器
class ArcController extends CommonController{
	private $model;
	public function __auto(){
		$this->model = new \Common\Model\Arc;
	}
	//显示文章
	public function index(){
		//获得数据
		$data = $this->model->getArcCate();
		View::with('data',$data);
	    View::make();
	}
	//添加文章
	public function add(){
		if(IS_POST){
			//调用模型添加
			if($this->model->store()){
				View::success('添加成功',U('index'));
			}
			View::error($this->model->getError());
		}
		//处理“所属分类”
		$model = new \Common\Model\Cate;
		View::with('cateData',Data::tree($model->get(),'cname'));
		//处理“所有标签”
		$tagModel = new \Common\Model\Tag;
		$tagData = $tagModel->get();
		View::with('tagData',$tagData);
		//载入模板
	    View::make();
	}
	//删除到回收站（其实就是把is_recycle改为1）
	public function del(){
		$aid = Q('get.aid',0,'intval');
		$this->model->where("aid={$aid}")->save(array('is_recycle'=>1));
	    View::success('已放入回收站');
	}
	//从回收站真正的删除
	public function readDel(){
	    View::make();
	}
	public function edit(){
		//二、修改
		if(IS_POST){
		    if($this->model->edit(Q('get.aid',0,'intval'))){
		    		View::success('修改成功',U('index'));
		    }
			View::error($this->model->getError());
		    //$this->success();
		}
		
		//一、获得旧数据
		$aid = Q('get.aid',0,'intval');
		$oldData = $this->model->join("article_data",'aid','=','article_aid')->where("aid={$aid}")->find();
		View::with('oldData',$oldData);
		//处理“所属分类”
		$cateModel = new \Common\Model\Cate;
		$cateData = Data::tree($cateModel->get(),'cname');
		View::with('cateData',$cateData);
		//处理“标签”
		$tagModel = new \Common\Model\Tag;
		$tagData = $tagModel->get();
		View::with('tagData',$tagData);
		
		//获得当前文章选中的那些标签的id
		$arcTagModel = new \Common\Model\ArcTag;
		$tids = $arcTagModel->where("article_aid={$aid}")->lists('tag_tid');
		View::with('tids',$tids);
		
	    View::make();
	}
	//回收站
	public function recycle(){
	    View::make();
	}
	
	
	
	
	
}
	